package com.nbsaas.boot.site.data.entity;


import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.CatalogEntity;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@org.hibernate.annotations.Table(appliesTo = "bs_page_catalog", comment = "页面分类")
@Data
@FormAnnotation(title = "页面分类", model = "页面分类")
@Entity
@Table(name = "bs_page_catalog")
@CatalogClass
public class DynamicPageCatalog extends CatalogEntity {


    @FormField(title = "分类图标", type = InputType.image)
    private String logo;

    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private DynamicPageCatalog parent;

    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    private List<DynamicPageCatalog> children;

    @Override
    public Serializable getParentId() {
        if (parent != null) {
            return parent.getId();
        }
        return null;
    }
}
